package com.guofen.controller.sjq;


import com.guofen.pojo.SjqWaterProductionBackwashing;
import com.guofen.service.sjq.SjqWaterProductionBackwashingService;
import com.guofen.util.result.Result;
import com.guofen.util.result.ResultGenerator;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@RequestMapping("/sjq/SjqWaterProductionBackwashing")
@Controller
@Api(tags = "SjqWaterProductionBackwashingController", description = "水处理膜反洗")
public class SjqWaterProductionBackwashingController {
    @Autowired
    private SjqWaterProductionBackwashingService sjqWaterProductionBackwashingService;

    @ApiOperation("1#膜组件添加开机时间（按钮序号为0）")
    @RequestMapping(value = "/addontime1", method = RequestMethod.POST)
    @ResponseBody
    public Result addontime1(@ApiParam(name = "num", value = "按钮序号", required = true) @RequestParam int num){
        if (sjqWaterProductionBackwashingService.addontime1(num))
            return ResultGenerator.genSuccessResult();
        else
            return ResultGenerator.genFailResult("保存失败");
    }
    @ApiOperation("1#膜组件添加关机时间（按钮序号为1）")
    @RequestMapping(value = "/addofftime1", method = RequestMethod.POST)
    @ResponseBody
    public Result addofftime1(@ApiParam(name = "num", value = "按钮序号", required = true) @RequestParam int num){
        if (sjqWaterProductionBackwashingService.addofftime1(num))
            return ResultGenerator.genSuccessResult();
        else
            return ResultGenerator.genFailResult("保存失败");
    }
    @ApiOperation("1#膜组件流量是否为5（按钮序号为2）")
    @RequestMapping(value = "/addisfive1", method = RequestMethod.POST)
    @ResponseBody
    public Result addisfive1(@ApiParam(name = "num", value = "按钮序号", required = true) @RequestParam int num,
                             @ApiParam(name = "yn", value = "是否", required = true) @RequestParam String yn,
                             @ApiParam(name = "reason", value = "原因", required = false) @RequestParam String reason){
        if (sjqWaterProductionBackwashingService.addisfive1(num,yn,reason))
            return ResultGenerator.genSuccessResult();
        else
            return ResultGenerator.genFailResult("保存失败");
    }
    @ApiOperation("2#膜组件添加开机时间（按钮序号为3）")
    @RequestMapping(value = "/addontime2", method = RequestMethod.POST)
    @ResponseBody
    public Result addontime2(@ApiParam(name = "num", value = "按钮序号", required = true) @RequestParam int num){
        if (sjqWaterProductionBackwashingService.addontime2(num))
            return ResultGenerator.genSuccessResult();
        else
            return ResultGenerator.genFailResult("保存失败");
    }
    @ApiOperation("2#膜组件添加关机时间（按钮序号为4）")
    @RequestMapping(value = "/addofftime2", method = RequestMethod.POST)
    @ResponseBody
    public Result addofftime2(@ApiParam(name = "num", value = "按钮序号", required = true) @RequestParam int num){
        if (sjqWaterProductionBackwashingService.addofftime2(num))
            return ResultGenerator.genSuccessResult();
        else
            return ResultGenerator.genFailResult("保存失败");
    }
    @ApiOperation("2#膜组件流量是否为5（按钮序号为5）")
    @RequestMapping(value = "/addisfive2", method = RequestMethod.POST)
    @ResponseBody
    public Result addisfive2(@ApiParam(name = "num", value = "按钮序号", required = true) @RequestParam int num,
                             @ApiParam(name = "yn", value = "是否", required = true) @RequestParam String yn,
                             @ApiParam(name = "reason", value = "原因", required = false) @RequestParam String reason){
        if (sjqWaterProductionBackwashingService.addisfive2(num,yn,reason))
            return ResultGenerator.genSuccessResult();
        else
            return ResultGenerator.genFailResult("保存失败");
    }
    @ApiOperation("3#膜组件添加开机时间（按钮序号为6）")
    @RequestMapping(value = "/addontime3", method = RequestMethod.POST)
    @ResponseBody
    public Result addontime3(@ApiParam(name = "num", value = "按钮序号", required = true) @RequestParam int num){
        if (sjqWaterProductionBackwashingService.addontime3(num))
            return ResultGenerator.genSuccessResult();
        else
            return ResultGenerator.genFailResult("保存失败");
    }
    @ApiOperation("3#膜组件添加关机时间（按钮序号为7）")
    @RequestMapping(value = "/addofftime3", method = RequestMethod.POST)
    @ResponseBody
    public Result addofftime3(@ApiParam(name = "num", value = "按钮序号", required = true) @RequestParam int num){
        if (sjqWaterProductionBackwashingService.addofftime3(num))
            return ResultGenerator.genSuccessResult();
        else
            return ResultGenerator.genFailResult("保存失败");
    }
    @ApiOperation("3#膜组件流量是否为5（按钮序号为8）")
    @RequestMapping(value = "/addisfive3", method = RequestMethod.POST)
    @ResponseBody
    public Result addisfive3(@ApiParam(name = "num", value = "按钮序号", required = true) @RequestParam int num,
                             @ApiParam(name = "yn", value = "是否", required = true) @RequestParam String yn,
                             @ApiParam(name = "reason", value = "原因", required = false) @RequestParam String reason){
        if (sjqWaterProductionBackwashingService.addisfive3(num,yn,reason))
            return ResultGenerator.genSuccessResult();
        else
            return ResultGenerator.genFailResult("保存失败");
    }
    @ApiOperation("水温实测值")
    @RequestMapping(value = "/addvalue", method = RequestMethod.POST)
    @ResponseBody
    public Result addvalue(@ApiParam(name = "value", value = "实测值", required = true) @RequestParam Double value){
        if (sjqWaterProductionBackwashingService.addvalue(value))
            return ResultGenerator.genSuccessResult();
        else
            return ResultGenerator.genFailResult("保存失败");
    }
    @ApiOperation("水温是否大于5（按钮序号为9）")
    @RequestMapping(value = "/addisfive4", method = RequestMethod.POST)
    @ResponseBody
    public Result addisfive4(@ApiParam(name = "num", value = "按钮序号", required = true) @RequestParam int num,
                             @ApiParam(name = "yn", value = "是否", required = true) @RequestParam String yn,
                             @ApiParam(name = "reason", value = "原因", required = false) @RequestParam String reason){
        if (sjqWaterProductionBackwashingService.addisfive4(num,yn,reason))
            return ResultGenerator.genSuccessResult();
        else
            return ResultGenerator.genFailResult("保存失败");
    }
    @ApiOperation("添加药剂信息")
    @RequestMapping(value = "/addinfo", method = RequestMethod.POST)
    @ResponseBody
    public Result addinfo(@ApiParam(name = "drug_name", value = "药剂名称", required = true) @RequestParam String drug_name,
                          @ApiParam(name = "drug_specifications", value = "药剂规格", required = true) @RequestParam String drug_specifications,
                          @ApiParam(name = "drug_dosage", value = "药剂量", required = true) @RequestParam Double drug_dosage,
                          @ApiParam(name = "add_water", value = "加水量", required = true) @RequestParam Double add_water,
                          @ApiParam(name = "remarks", value = "备注", required = false) @RequestParam String remarks){
        if (sjqWaterProductionBackwashingService.addinfo(drug_name,drug_specifications,drug_dosage,add_water,remarks))
            return ResultGenerator.genSuccessResult();
        else
            return ResultGenerator.genFailResult("保存失败");
    }
    @ApiOperation("获取1#膜组件运行时间")
    @RequestMapping(value = "/getruntime1", method = RequestMethod.GET)
    @ResponseBody
    public Result getruntime1(){
        return ResultGenerator.genSuccessResult(sjqWaterProductionBackwashingService.getruntime1());
    }
    @ApiOperation("获取2#膜组件运行时间")
    @RequestMapping(value = "/getruntime2", method = RequestMethod.GET)
    @ResponseBody
    public Result getruntime2(){
        return ResultGenerator.genSuccessResult(sjqWaterProductionBackwashingService.getruntime2());
    }
    @ApiOperation("获取3#膜组件运行时间")
    @RequestMapping(value = "/getruntime3", method = RequestMethod.GET)
    @ResponseBody
    public Result getruntime3(){
        return ResultGenerator.genSuccessResult(sjqWaterProductionBackwashingService.getruntime3());
    }


    @ApiOperation("删除记录")
    @RequestMapping(value = "/delete",method = RequestMethod.POST)
    @ResponseBody
    public Result delete(@ApiParam(name="id",value="ID",required=true) @RequestParam Integer id) {
        return ResultGenerator.genSuccessResult(sjqWaterProductionBackwashingService.delete(id));
    }

    @ApiOperation("修改记录")
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    @ResponseBody
    public Result update(@ApiParam(name="id",value="ID",required=true) @RequestParam Integer id,
                         @ApiParam(name="plan_backwashing_date",value="计划膜反洗日期",required=true) @RequestParam String plan_backwashing_date,
                         @ApiParam(name="actual_backwashing_date",value="实际膜反洗日期",required=true) @RequestParam String actual_backwashing_date,
                         @ApiParam(name="backwashing_pump_open_time_1",value="反洗泵开机时间1",required=true) @RequestParam String backwashing_pump_open_time_1,
                         @ApiParam(name="backwashing_pump_close_timer_1",value="反洗泵关机时间1",required=true) @RequestParam String backwashing_pump_close_timer_1,
                         @ApiParam(name="backwashing_pump_running_time_1",value="反洗泵运行时间1",required=true) @RequestParam String backwashing_pump_running_time_1,
                         @ApiParam(name="is_running_time_24_1",value="反洗泵运行时间是否1",required=true) @RequestParam String is_running_time_24_1,
                         @ApiParam(name="is_flowmeter_5_1",value="流量计流量是否为5m³/h1",required=true) @RequestParam String is_flowmeter_5_1,
                         @ApiParam(name="backwashing_pump_open_time_2",value="反洗泵开机时间2",required=true) @RequestParam String backwashing_pump_open_time_2,
                         @ApiParam(name="backwashing_pump_close_timer_2",value="反洗泵关机时间2",required=true) @RequestParam String backwashing_pump_close_timer_2,
                         @ApiParam(name="backwashing_pump_running_time_2",value="反洗泵运行时间2",required=true) @RequestParam String backwashing_pump_running_time_2,
                         @ApiParam(name="is_running_time_24_2",value="反洗泵运行时间是否2",required=true) @RequestParam String is_running_time_24_2,
                         @ApiParam(name="is_flowmeter_5_2",value="流量计流量是否为5m³/h2",required=true) @RequestParam String is_flowmeter_5_2,
                         @ApiParam(name="backwashing_pump_open_time_3",value="反洗泵开机时间3",required=true) @RequestParam String backwashing_pump_open_time_3,
                         @ApiParam(name="backwashing_pump_close_timer_3",value="反洗泵关机时间3",required=true) @RequestParam String backwashing_pump_close_timer_3,
                         @ApiParam(name="backwashing_pump_running_time_3",value="反洗泵运行时间3",required=true) @RequestParam String backwashing_pump_running_time_3,
                         @ApiParam(name="is_running_time_24_3",value="反洗泵运行时间是否3",required=true) @RequestParam String is_running_time_24_3,
                         @ApiParam(name="is_flowmeter_5_3",value="流量计流量是否为5m³/h3",required=true) @RequestParam String is_flowmeter_5_3,
                         @ApiParam(name="drug_name",value="药剂名称",required=true) @RequestParam String drug_name,
                         @ApiParam(name="drug_specifications",value="药剂规格",required=true) @RequestParam String drug_specifications,
                         @ApiParam(name="drug_dosage",value="药剂量",required=true) @RequestParam String drug_dosage,
                         @ApiParam(name="add_water",value="加水量",required=true) @RequestParam String add_water,
                         @ApiParam(name="remarks",value="备注",required=false) @RequestParam String remarks,
                         @ApiParam(name="measured_value",value="实测值",required=true) @RequestParam String measured_value,
                         @ApiParam(name="is_higher_5",value="是否>5℃",required=true) @RequestParam String is_higher_5) {
        double drugDosage = Double.parseDouble(drug_dosage);
        double addWater = Double.parseDouble(add_water);
        double measuredValue = Double.parseDouble(measured_value);

        SjqWaterProductionBackwashing record = new SjqWaterProductionBackwashing();
        record.setId(id);
        record.setPlanBackwashingDate(plan_backwashing_date);
        record.setActualBackwashingDate(actual_backwashing_date);
        record.setBackwashingPumpOpenTime1(backwashing_pump_open_time_1);
        record.setBackwashingPumpCloseTimer1(backwashing_pump_close_timer_1);
        record.setBackwashingPumpRunningTime1(backwashing_pump_running_time_1);
        record.setIsRunningTime241(is_running_time_24_1);
        record.setIsFlowmeter51(is_flowmeter_5_1);
        record.setBackwashingPumpOpenTime2(backwashing_pump_open_time_2);
        record.setBackwashingPumpCloseTimer2(backwashing_pump_close_timer_2);
        record.setBackwashingPumpRunningTime2(backwashing_pump_running_time_2);
        record.setIsRunningTime242(is_running_time_24_2);
        record.setIsFlowmeter52(is_flowmeter_5_2);
        record.setBackwashingPumpOpenTime2(backwashing_pump_open_time_3);
        record.setBackwashingPumpCloseTimer2(backwashing_pump_close_timer_3);
        record.setBackwashingPumpRunningTime2(backwashing_pump_running_time_3);
        record.setIsRunningTime242(is_running_time_24_3);
        record.setIsFlowmeter52(is_flowmeter_5_3);
        record.setDrugName(drug_name);
        record.setDrugSpecifications(drug_specifications);
        record.setDrugDosage(drugDosage);
        record.setAddWater(addWater);
        record.setRemarks(remarks);
        record.setMeasuredValue(measuredValue);
        record.setIsHigher5(is_higher_5);
        return ResultGenerator.genSuccessResult(sjqWaterProductionBackwashingService.update(record));
    }

    @ApiOperation("查找记录")
    @RequestMapping(value = "/select",method = RequestMethod.POST)
    @ResponseBody
    public Result select(@ApiParam(name="pageSize",value="页容量",required=true) @RequestParam Integer pageSize,
                         @ApiParam(name="currentPage",value="当前页",required=true) @RequestParam Integer currentPage,
                         @ApiParam(name="startTime",value="开始时间") Long startTime,
                         @ApiParam(name="endTime",value="截止时间") Long endTime) {
        if (startTime == null || endTime == null)
            return ResultGenerator.genSuccessResult(sjqWaterProductionBackwashingService.get(pageSize, currentPage));
        else
            return ResultGenerator.genSuccessResult(sjqWaterProductionBackwashingService.getByTime(pageSize, currentPage, startTime, endTime));
    }
}
